
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
  <head>
    <meta charset="utf-8" />
    <title>stringprep --- 因特网字符串预备 &#8212; Python 3.7.8 文档</title>
    <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/translations.js"></script>
    
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    
    <link rel="search" type="application/opensearchdescription+xml"
          title="在 Python 3.7.8 文档 中搜索"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="关于这些文档" href="../about.html" />
    <link rel="index" title="索引" href="../genindex.html" />
    <link rel="search" title="搜索" href="../search.html" />
    <link rel="copyright" title="版权所有" href="../copyright.html" />
    <link rel="next" title="readline --- GNU readline 接口" href="readline.html" />
    <link rel="prev" title="unicodedata --- Unicode 数据库" href="unicodedata.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
    <link rel="canonical" href="https://docs.python.org/3/library/stringprep.html" />
    
    <script type="text/javascript" src="../_static/copybutton.js"></script>
    
    
    
    
    <style>
      @media only screen {
        table.full-width-table {
            width: 100%;
        }
      }
    </style>
 

  </head><body>
  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             accesskey="I">索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="readline.html" title="readline --- GNU readline 接口"
             accesskey="N">下一页</a> |</li>
        <li class="right" >
          <a href="unicodedata.html" title="unicodedata --- Unicode 数据库"
             accesskey="P">上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="text.html" accesskey="U">文本处理服务</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>    

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <div class="section" id="module-stringprep">
<span id="stringprep-internet-string-preparation"></span><h1><a class="reference internal" href="#module-stringprep" title="stringprep: String preparation, as per RFC 3453"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code></a> --- 因特网字符串预备<a class="headerlink" href="#module-stringprep" title="永久链接至标题">¶</a></h1>
<p><strong>源代码:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.7/Lib/stringprep.py">Lib/stringprep.py</a></p>
<hr class="docutils" />
<p>在标识因特网上的事物（例如主机名），经常需要比较这些标识是否（相等）。 这种比较的具体执行可能会取决于应用域的不同，例如是否要区分大小写等等。 有时也可能需要限制允许的标识为仅由“可打印”字符组成。</p>
<p><span class="target" id="index-4"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc3454.html"><strong>RFC 3454</strong></a> 定义了在因特网协议中 Unicode 字符串的“预备”过程。 在将字符串连线传输之前，它们会先使用预备过程进行处理，之后它们将具有特定的标准形式。 该 RFC 定义了一系列表格，它们可以被组合为选项配置。 每个配置必须定义所使用的表格，<code class="docutils literal notranslate"><span class="pre">stringprep</span></code> 过程的其他可选项也是配置的组成部分。 <code class="docutils literal notranslate"><span class="pre">stringprep</span></code> 配置的一个例子是 <code class="docutils literal notranslate"><span class="pre">nameprep</span></code>，它被用于国际化域名。</p>
<p>模块 <a class="reference internal" href="#module-stringprep" title="stringprep: String preparation, as per RFC 3453"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code></a> 仅公开了来自 <span class="target" id="index-5"></span><a class="rfc reference external" href="https://tools.ietf.org/html/rfc3454.html"><strong>RFC 3454</strong></a> 的表格。 由于这些如果表格如果表示为字典或列表将会非常庞大，该模块在内部使用 Unicode 字符数据库。 该模块本身的源代码是使用 <code class="docutils literal notranslate"><span class="pre">mkstringprep.py</span></code> 工具生成的。</p>
<p>因此，这些表格以函数而非数据结构的形式公开。 在 RFC 中有两种表格：集合与映射。 对于集合，<a class="reference internal" href="#module-stringprep" title="stringprep: String preparation, as per RFC 3453"><code class="xref py py-mod docutils literal notranslate"><span class="pre">stringprep</span></code></a> 提供了“特征函数”，即如果形参是集合的一部分则返回值为 <code class="docutils literal notranslate"><span class="pre">True</span></code> 的函数。 对于映射，它提供了映射函数：它会根据给定的键返回所关联的值。 以下是模块中所有可用函数的列表。</p>
<dl class="function">
<dt id="stringprep.in_table_a1">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_a1</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_a1" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableA.1 (Unicode 3.2 中的未分配码位)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_b1">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_b1</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_b1" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableB.1 (通常映射为空值)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.map_table_b2">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">map_table_b2</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.map_table_b2" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>code</em> 依据 tableB.2 (配合 NFKC 使用的大小写转换映射) 所映射的值。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.map_table_b3">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">map_table_b3</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.map_table_b3" title="永久链接至目标">¶</a></dt>
<dd><p>返回 <em>code</em> 依据 tableB.3 (不附带正规化的大小写折叠映射) 所映射的值。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c11">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c11</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c11" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.1.1  (ASCII 空白字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c12">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c12</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c12" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.1.2  (非 ASCII 空白字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c11_c12">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c11_c12</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c11_c12" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.1  (空白字符，C.1.1 和 C.1.2 的并集)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c21">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c21</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c21" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.2.1  (ASCII 控制字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c22">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c22</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c22" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.2.2  (非 ASCII 控制字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c21_c22">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c21_c22</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c21_c22" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.2  (控制字符，C.2.1 和 C.2.2 的并集)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c3">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c3</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c3" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.3  (私有使用)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c4">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c4</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c4" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.4  (非字符码位)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c5">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c5</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c5" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.5  (替代码)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c6">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c6</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c6" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.6  (不适用于纯文本)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c7">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c7</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c7" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.7  (不适用于规范表示)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c8">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c8</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c8" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.8  (改变显示属性或已弃用)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_c9">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_c9</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_c9" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableC.9  (标记字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_d1">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_d1</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_d1" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableD.1  (带有双向属性 &quot;R&quot; 或 &quot;AL&quot; 的字符)。</p>
</dd></dl>

<dl class="function">
<dt id="stringprep.in_table_d2">
<code class="sig-prename descclassname">stringprep.</code><code class="sig-name descname">in_table_d2</code><span class="sig-paren">(</span><em class="sig-param">code</em><span class="sig-paren">)</span><a class="headerlink" href="#stringprep.in_table_d2" title="永久链接至目标">¶</a></dt>
<dd><p>确定 <em>code</em> 是否属于 tableD.2  (带有双向属性 &quot;L&quot; 的字符)。</p>
</dd></dl>

</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
  <h4>上一个主题</h4>
  <p class="topless"><a href="unicodedata.html"
                        title="上一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">unicodedata</span></code> --- Unicode 数据库</a></p>
  <h4>下一个主题</h4>
  <p class="topless"><a href="readline.html"
                        title="下一章"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code> --- GNU readline 接口</a></p>
  <div role="note" aria-label="source link">
    <h3>本页</h3>
    <ul class="this-page-menu">
      <li><a href="../bugs.html">提交 Bug</a></li>
      <li>
        <a href="https://github.com/python/cpython/blob/3.7/Doc/library/stringprep.rst"
            rel="nofollow">显示源代码
        </a>
      </li>
    </ul>
  </div>
        </div>
      </div>
      <div class="clearer"></div>
    </div>  
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>导航</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="总目录"
             >索引</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python 模块索引"
             >模块</a> |</li>
        <li class="right" >
          <a href="readline.html" title="readline --- GNU readline 接口"
             >下一页</a> |</li>
        <li class="right" >
          <a href="unicodedata.html" title="unicodedata --- Unicode 数据库"
             >上一页</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="https://www.python.org/">Python</a> &#187;</li>
        <li>
          <a href="../index.html">3.7.8 Documentation</a> &#187;
        </li>

          <li class="nav-item nav-item-1"><a href="index.html" >Python 标准库</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="text.html" >文本处理服务</a> &#187;</li>
    <li class="right">
        

    <div class="inline-search" style="display: none" role="search">
        <form class="inline-search" action="../search.html" method="get">
          <input placeholder="快速搜索" type="text" name="q" />
          <input type="submit" value="转向" />
          <input type="hidden" name="check_keywords" value="yes" />
          <input type="hidden" name="area" value="default" />
        </form>
    </div>
    <script type="text/javascript">$('.inline-search').show(0);</script>
         |
    </li>

      </ul>
    </div>  
    <div class="footer">
    &copy; <a href="../copyright.html">版权所有</a> 2001-2020, Python Software Foundation.
    <br />
    Python 软件基金会是一个非盈利组织。
    <a href="https://www.python.org/psf/donations/">请捐助。</a>
    <br />
    最后更新于 6月 29, 2020.
    <a href="../bugs.html">发现了问题</a>？
    <br />
    使用<a href="http://sphinx.pocoo.org/">Sphinx</a>2.3.1 创建。
    </div>

  </body>
</html>